home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
ulib
/
bbox.c
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
68 lines
/************************************************************************
* $Id: bbox.c,v 0.80 1994/02/24 09:48:11 zhao Exp $
*
*. Copyright(c) 1993,1994 by T.C. Zhao
* All rights reserved.
*.
*
* Find the bounding box of a rotated rectangle.
* The rectangle is centered at (x,y) and has a width w and a height h.
***********************************************************************/
#if !defined(lint) && defined(F_ID)
char *id_bbox = "$Id: bbox.c,v 0.80 1994/02/24 09:48:11 zhao Exp $";
#endif
#include "ulib.h"
#include <math.h>
void
find_bbox(int x, int y, int w, int h, float ia,
int *bx, int *by, int *bw, int *bh)
{
double fx[4], fy[4], sa, ca;
double xi, xf, yi, yf;
double pi = acos(-1.0);
int i;
if (Abs(ia) < 1.0e-5)
{
*bx = x - (w + 1) / 2;
*by = y - (h + 1) / 2;
*bw = w + 2;
*bh = h + 2;
return;
}
sa = sin(ia * pi / 180.0);
ca = cos(ia * pi / 180.0);
fx[0] = (-w * ca + h * sa) * 0.5 + x;
fy[0] = (-w * sa - h * ca) * 0.5 + y;
fx[1] = (w * ca + h * sa) * 0.5 + x;
fy[1] = (w * sa - h * ca) * 0.5 + y;
fx[2] = (w * ca - h * sa) * 0.5 + x;
fy[2] = (w * sa + h * ca) * 0.5 + y;
fx[3] = (-w * ca - h * sa) * 0.5 + x;
fy[3] = (-w * sa + h * ca) * 0.5 + y;
/* find the bbox */
xi = xf = fx[0];
yi = yf = fy[0];
for (i = 1; i < 4; i++)
{
xi = Min(xi, fx[i]);
xf = Max(xf, fx[i]);
yi = Min(yi, fy[i]);
yf = Max(yf, fy[i]);
}
*bx = (xi - 1.5);
*by = (yi - 1.5);
*bw = (xf - xi + 2.8);
*bh = (yf - yi + 2.8);
}